package com.ruoyi.qualityControl.utils;

import net.java.games.input.*;


public class test {
    public static void main(String[] args) {
        try {
            // 获取默认的ControllerEnvironment实例
            ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();

            System.out.println(System.getProperty("java.library.path"));
            // 获取所有控制器（包括joystick）
            Controller[] controllers = ce.getControllers();
            for (Controller controller : controllers) {
                if (controller.getType() == Controller.Type.STICK) {
                    System.out.println("Found joystick: " + controller.getName().substring(0,8));
                    while (true) {
                        // 更新控制器状态
                        controller.poll();
                        // 获取按键状态
                        Component[] components = controller.getComponents();
                        for (Component component : components) {
//                            System.out.println("Identifier: " + component.getIdentifier());
//                            System.out.println("pollData: " + component.getPollData());
//                            System.out.println("name: " + component.getName());
//                            System.out.println("DeadZone: " + component.getDeadZone());
                            float pollData = component.getPollData();
                            if (component.isAnalog()) {
                                System.out.println(component.getIdentifier()+"：" + pollData);
                            } else {
                                System.out.println(component.getIdentifier() +"：" + pollData);
                            }
                        }
                        // 等待一段时间，避免过于频繁的读取
                        Thread.sleep(1000);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
